<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>验证码</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f7f7f7;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        #container {
            text-align: center;
            background: white;
            padding: 50px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #333;
            font-size: 2em;
            margin-bottom: 20px;
        }
        #inputCaptcha {
            height: 40px;
            margin-right: 10px;
            vertical-align: middle;
            border: 1px solid #ddd;
            border-radius: 4px;
            padding: 0 10px;
        }
        #verificationCodeImg {
            vertical-align: middle;
            border: 1px solid #ddd;
            cursor: pointer;
            transition: transform 0.2s;
        }
        #verificationCodeImg:hover {
            transform: scale(1.05);
        }
        #checkCaptcha {
            height: 40px;
            width: 120px;
            background-color: #5cb85c;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        #checkCaptcha:hover {
            background-color: #4cae4c;
        }
    </style>
</head>

<body>
<div id="container">
    <h1>输入验证码</h1>
    <div id="confirm">
        <input type="text" name="inputCaptcha" id="inputCaptcha">
        <img id="verificationCodeImg" src="http://127.0.0.1:8080/captcha/getCaptcha" style="cursor: pointer;"
             title="看不清？换一张"/>
        <input type="button" value="提交" id="checkCaptcha">
    </div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
    $("#verificationCodeImg").click(function () {
        $(this).hide().attr('src', 'http://127.0.0.1:8080/captcha/getCaptcha?dt=' + new Date().getTime()).fadeIn();
    });

    $("#checkCaptcha").click(function () {
        $.ajax({
            type: "post",
            url: "captcha/check",
            data: {
                captcha: $("#inputCaptcha").val()
            },
            success: function (result) {
                if (result) {
                    location.href = "success.html"
                } else {
                    alert("验证码错误")
                }
            }
        });
    });
</script>
</body>

</html>